package com.wa.handler;

import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.listener.DataListener;
import com.wa.constants.WebSocketEventConstant;
import com.wa.vo.BomWebSocketPackage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 这里为了兼容以前的代码, 没有通过事件方式路由, 而是采用了固定的包格式通过类型区分, 这种方式需要自己拆包, 编码比较后面的代码请不要使用了
 *
 * @author recharde.li@allchips.com
 * @version V1.0
 * @date 2020-06-01 09:43
 **/
@Component
@SuppressWarnings("rawtypes")
public class BomNamespaceMessageEventHandler implements DataListener<BomWebSocketPackage> {

    final static private Logger logger = LoggerFactory.getLogger(BomNamespaceMessageEventHandler.class);

//    @Resource
//    private IBomWebSocketMessageDispatcherApi bomWebSocketMessageDispatcherApi;

    @Override
    @SuppressWarnings("unchecked")
    public void onData(SocketIOClient socketIOClient, BomWebSocketPackage pkg, AckRequest ackRequest) {
        try {
//            bomWebSocketMessageDispatcherApi.dispatch(pkg, socketIOClient.getSessionId().toString());
        } catch (Exception e) {
            socketIOClient.sendEvent(WebSocketEventConstant.MESSAGE_EVENT, "bom服务挂掉了");
            logger.error("处理协同前端消息异常", e);
        }
    }

}
